package com.example.controller;

import com.example.datasource.CurDataSource;
import com.example.datasource.DataSourceNames;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 系统用户 前端控制器
 * </p>
 *
 * @author xiaohe
 * @since 2019-06-04
 */
@RestController
@RequestMapping("/sys-user")
public class SysUserController {
    @Autowired
    JdbcTemplate jdbcTemplate;

    @CurDataSource(name = DataSourceNames.SLAVE1)
    @RequestMapping("/get")
    public String get(){
        System.out.println(1);
        jdbcTemplate.query("select * from mcms_archives limit 4", new RowMapper<Map>() {
            @Override
            public Map mapRow(ResultSet rs, int rowNum) throws SQLException {
                Map row = new HashMap();
                System.out.println(rs.getInt("id"));
                return row;
            }
        });
        return "a";
    }
}
